{% init show_path_list = False %}
{% init error = None %}
{% init group_type = None %}
{% init op = "view" %}
{% init is_iframe = False %}

{% set item = file %}
{% set type_dict = dict(
    md = "Markdown",
    gallery = "相册",
    html = "富文本",
    csv = "表格"
) %}

{% if show_path_list %}
    <div class="grid-title">
        {% for i, path_item in enumerate(pathlist) %}
            {% if i > 0 %} / {% end %}<a href="{{path_item.url}}" class="link2 path-link">{{ path_item.name }}</a>
        {% end %}

        {% if file != None and file.type == "group" and _user_name == file.creator %}
            {# 文件夹下拉选项 #}
            <div class="float-right">
                <a class="btn" href="/note/add?parent_id={{file.id}}">新增</a>
                <div class="dropdown">
                  <span class="dropdown-btn link btn">更多▾</span>
                  <div class="dropdown-content">                            
                    {% if file.priority > 0 %}
                        <a class="dropdown-option" href="/note/unstick?id={{file.id}}">取消置顶</a>
                    {% else %}
                        <a class="dropdown-option" href="/note/stick?id={{file.id}}">置顶</a>
                    {% end %}

                    {% if file.archived %}
                        <a class="dropdown-option" href="/note/unarchive?id={{file.id}}">取消归档</a>
                    {% else %}
                        <a class="dropdown-option" href="/note/archive?id={{file.id}}">归档</a>
                    {% end %}

                    <a class="dropdown-option" href="/note/management?parent_id={{file.id}}">整理</a>
                    <a class="dropdown-option" href="javascript:rename('{{file.id}}', '{{file.name}}')">重命名</a>
                    <a class="dropdown-option" href="/note/view?id={{file.id}}&orderby=mtime_desc&page={{page}}">按时间倒序</a>
                    <a class="dropdown-option" href="/note/view?id={{file.id}}&orderby=name&page={{page}}">按名称顺序</a>
                    <a class="dropdown-option" href="/note/view?id={{file.id}}&orderby=name_desc&page={{page}}">按名称倒序</a>
                    
                    {% if file.size == 0 %}
                        <a class="dropdown-option-red" href="javascript:remove('{{file.id}}', '{{file.name}}')">删除</a>
                    {% end %}
                  </div>
                </div>
            </div>
        {% elif group_type == "gallery" %}
            <div class="float-right"><a class="btn" href="/note/add?type=gallery">创建相册</a></div>
        {% else %}
            {# 其他普通笔记 #}
            <div class="float-right">
                {% if file != None and _user_name == file.creator and op == "view" %}
                <a class="btn" href="/note/edit?id={{file.id}}&is_iframe={{is_iframe}}">编辑</a>
                <div class="dropdown">
                    <span class="dropdown-btn link btn">更多▾</span>
                    <div class="dropdown-content">
                        <a class="dropdown-option link" href="javascript:rename('{{item.id}}', '{{item.name}}')">重命名</a>
                        {% if file.is_public %}
                            <a class="dropdown-option link" href="/note/share/cancel?id={{file.id}}">取消分享</a>
                        {% else %}
                            <a class="dropdown-option link" href="/note/share?id={{file.id}}">分享</a>
                        {% end %}
                        <a class="dropdown-option move-btn link" data-url="/note/group/select?id={{item.id}}">移动</a>
                        {% if file.priority > 0 %}
                            <a class="dropdown-option link" href="/note/unstick?id={{file.id}}">取消置顶</a>
                        {% else %}
                            <a class="dropdown-option link" href="/note/stick?id={{file.id}}">置顶</a>
                        {% end %}

                        <a class="dropdown-option link" href="/note/history?id={{file_id}}">{{T("History")}}</a>

                        {% if _is_admin and file.type == "gallery" %}
                            <a class="dropdown-option link" href="/fs/{{file.path}}">管理文件</a>
                        {% end %}

                        <a class="dropdown-option link" href="/note/print?id={{file.id}}" target="_blank">打印模式</a>

                        <a class="dropdown-option-red" href="javascript:remove('{{item.id}}', '{{item.name}}', '{{item.parent_id}}')">删除</a>
                    </div>
                </div>
                {% end %}
                <!-- <a href="javascript:history.back()">返回</a> -->
            </div>
        {% end %}
    </div>
{% end %}

{# 笔记的概要信息 #}
{% if item != None and item.type != "group" %}
    <div class="col-md-12" style="border-bottom:1px solid #ccc"> 
        <span id="fileId" style="display:none;">{{file.id}}</span>    
        <div class="col-md-12 hide">
            {% if _has_login and  (_is_admin or _user_name == item.creator) %}
                <a class="link" href="/note/edit?id={{file.id}}">编辑</a>
                <a class="link" href="javascript:rename('{{item.id}}', '{{item.name}}')">重命名</a>
                {% if file.is_public %}
                    <a class="link" href="/note/share/cancel?id={{file.id}}">取消分享</a>
                {% else %}
                    <a class="link" href="/note/share?id={{file.id}}">分享</a>
                {% end %}

                <a class="move-btn link" data-url="/note/group/select?id={{item.id}}">移动</a>
                
                {% if file.priority > 0 %}
                    <a class="link" href="/note/unstick?id={{file.id}}">取消置顶</a>
                {% else %}
                    <a class="link" href="/note/stick?id={{file.id}}">置顶</a>
                {% end %}

                {% if _is_admin and file.type == "gallery" %}
                    <a class="link" href="/fs/{{file.path}}">管理文件</a>
                {% end %}
                <!-- <a class="link" href="/note/print?id={{file.id}}" target="_blank">打印</a> -->
                <a class="red" href="javascript:remove('{{item.id}}', '{{item.name}}', '{{item.parent_id}}')">删除</a>
            {% end %}
        </div>

        <div>{{file.creator}} 创建于 {{file.ctime}} 更新于 {{file.mtime}} </div>

        <div class="row">
            <span>字数: {{len(item.content)}}</span>
            <span>行数: {{item.content.count("\n")}}</span>
            <span>类型: <a href="/note/{{item.type}}">{{type_dict.get(item.type, item.type)}}</a></span>
        </div>

        {% include note/view_tag.html %}
        <span id="result" style="color:green"></span>
    </div>
{% end %}


{% if error != "" and error != None%}
    <div class="col-md-12 error">
        {{error}}
    </div>
{% end %}
